package com.dyh.quickdemo.demos.mergeBool;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import javax.jws.soap.SOAPBinding;
import java.util.Random;

/*
@Author=Joey Wheeler
@Date=2020/11/9 10:20
*/
@Slf4j
public class MergeBoolTest {

    int i1 = 0x00000000;
    int i2 = 0xffffffff;

    @Setter@Getter@AllArgsConstructor
    class Mthread extends Thread{
        private int i;
        @SneakyThrows
        @Override
        public void run() {
            Random r = new Random();
            int sleep = r.nextInt(10)*100;
            log.info("{} sleep {} ms",Thread.currentThread().getName(),sleep);
            Thread.sleep(sleep);

            i1 = i1|(1<<(i-1));
        }
    }

    @Test
    public void test() throws InterruptedException {
        int count = 0;
        for (int i=1;i<=32;i++){
            Mthread mthread = new Mthread(i);
            mthread.start();
            count++;
        }

        Thread.sleep(1000L);
        System.out.println(count);
        System.out.println(Integer.toBinaryString(i1));
        System.out.println(Integer.toBinaryString(i1).length());
        System.out.println(Integer.toBinaryString(i2));
        System.out.println(Integer.toBinaryString(i2).length());
        System.out.println(Integer.toBinaryString(1).length());

    }


}
